<?php
namespace Admin\Controller;
use Cropper\Cropper;

class CropperController{
	//前台引入,ajax上传图片请求地址
	public function profile(){
		if(IS_POST){
			$width = isset($_GET['width'])?$_GET['width']:'200';
			$height =isset($_GET['height'])?$_GET['height']:'200';
			$crop = new Cropper($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file'],$width,$height);
			$response = array(
					'state'  => 200,
					'message' => $crop -> getMsg(),
					'result' => str_replace($_SERVER["DOCUMENT_ROOT"],'', $crop -> getResult())
			);
		}else{
			$response = array(
					'state'  => 200,
					'message' => '参数错误,重新选择',
					'result' => ''
			);
		}
		echo json_encode($response);
	}
}